<?php

namespace App\Console\Commands;

use Carbon\Carbon;
use App\Models\User;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;

class UsersCount extends Command
{
	protected $signature = 'cc:users-count';

	protected $description = "Users increasing statistic";

	public function __construct()
	{
		parent::__construct();
	}

	public function handle()
	{
		$this->info("Users are being counted...");

		$startDate = Carbon::today()->year(2021)->month(12)->day(17);
		$endDate = Carbon::today()->year(2022)->month(3)->day(9);

		while ($startDate) {

			$date = $startDate->addDay();

			$count = User::query()->whereDate('created_at', $date)->count();

			if ($date->gt($endDate) and $count <= 0) break;

			Log::info("{$date->toDateString()} - {$count}人");

			usleep(10);
		}
	}
}
